<?php
include 'DBconn.php';
class WarehouseMaster
{
public function getAllWarehouses()
{
    $result=mysql_query("select * from warehouse_header where activestatus=1") or die(mysql_error());
    $ret_arr=array();
    while($row=mysql_fetch_object($result))
    {
       $tmp=new VOWarehouseMaster();
       $tmp->serialnumber=(int)$row->serialnumber;
       $tmp->warehouse_id=$row->warehouse_id;
       $tmp->warehouse_name=$row->warehouse_name;
       $tmp->warehouse_description=$row->warehouse_description;
       $tmp->warehouse_email=$row->warehouse_email;
       $tmp->branch_serialnumber=(int)$row->branch_serialnumber;
       $tmp->cre_userid=(int)$row->cre_userid;
       $tmp->cre_datetime=$row->cre_datetime;
       $tmp->activestatus=(boolean)$row->activestatus;
       $ret_arr[]=$tmp; 
    }
    mysql_free_result($result);
    return $ret_arr;
}   
public function addNewWarehouse($VObject)
{
    $query="insert into warehouse_header(warehouse_id,warehouse_name,warehouse_description,warehouse_email,branch_serialnumber,cre_userid,cre_datetime,activestatus) values('$VObject->warehouse_id','$VObject->warehouse_name','$VObject->warehouse_description','$VObject->warehouse_email','$VObject->branch_serialnumber','$VObject->cre_userid','$VObject->cre_datetime',1)";
    $s=mysql_query($query) or die(mysql_error());
    if ($s=1) 
      {
        mysql_query("COMMIT");
      }
      else
      {
        mysql_query("ROLLBACK");
      }
      return $this->getAllWarehouses();
} 
public function deleteWarehouse($VObject)
{
    $s=mysql_query("update warehouse_header set activestatus=0 where serialnumber=".$VObject->serialnumber) or die(mysql_error());
    if ($s=1) 
      {
        mysql_query("COMMIT");
      }
      else
      {
        mysql_query("ROLLBACK");
      }
      return $this->getAllWarehouses();
}
public function editWarehouse($VObject)
{
    $query="update warehouse_header set warehouse_id='$VObject->warehouse_id',warehouse_name='$VObject->warehouse_name',warehouse_description='$VObject->warehouse_description',warehouse_email='$VObject->warehouse_email',branch_serialnumber='$VObject->branch_serialnumber',cre_userid='$VObject->cre_userid',cre_datetime='$VObject->cre_datetime' where serialnumber='$VObject->serialnumber'";
    $s=mysql_query($query) or die(mysql_error());
    if ($s=1) 
      {
        mysql_query("COMMIT");
      }
      else
      {
        mysql_query("ROLLBACK");
      }
      return $this->getAllWarehouses();
}
}
//$vo=new VOWarehouseMaster;
//$vo->serialnumber=3;
//$vo->branch_serialnumber=3;
//$vo->cre_userid=31;
//$vo->warehouse_id="5846";
//$vo->warehouse_email="abc@def.com";
//$d=new WarehouseMaster;
//#echo $d->addNewWarehouse($vo);
//echo $d->editWarehouse($vo);
class VOWarehouseMaster
{
  var $serialnumber;
  var $warehouse_id;
  var $warehouse_name;
  var $warehouse_description;
  var $warehouse_email;
  var $branch_serialnumber;
  var $cre_userid;
  var $cre_datetime;  
  var $activestatus;    
}
?>